package com.atguigu.cloud.payment8006.controller;


import com.atguigu.cloud.common.Person;

import com.atguigu.cloud.common.entity.Payment;
import com.atguigu.cloud.common.vo.CommonResult;
import com.atguigu.cloud.payment8006.service.PaymentService;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Value("${server.port}")
    private  String serverPort;
    @Resource
    PaymentService paymentService;

    @PostMapping("/create")
    public CommonResult create(@RequestBody Payment payment) {
        boolean isSaved
                = paymentService.saveOrUpdate(payment);
        if (!isSaved)
            return CommonResult.error();
        return CommonResult.ok().data("id",payment.getId());
    }

    @GetMapping("/get/{id}")
    public CommonResult get(@PathVariable String id) {
        Payment payment = paymentService.getById(id);
        if (payment == null)
            return CommonResult.error();


        Person person = new Person("zsc",19);
        return CommonResult.ok().data("payment", payment).data("person",person);
    }


    @GetMapping(value = "/consul")
    public CommonResult paymentConsul() {
        return CommonResult.ok().data("serverPort",serverPort);
    }
}
